import Vue from 'vue'
import Router from 'vue-router'
import store from '../assets/store.js'

Vue.use(Router);
const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/app',
      name: 'main_app',
      component: resolve => require(['../components/common/Main.vue'], resolve),
      children: [
        {
          path: '/',
          name: 'main',
          component: resolve => require(['../components/page/index.vue'], resolve),
        },
        {
          path: 'new',//子路由不要加/
          name: 'new',
          component: resolve => require(['../components/page/new/new.vue'], resolve),
        },
        {
          path: 'product',
          name: 'product',
          component: resolve => require(['../components/page/product/product.vue'], resolve),
        },
        {
          path: 'user',
          name: 'user',
          component: resolve => require(['../components/page/user/User.vue'], resolve),
        },
        {
          path: 'org',
          name: 'org',
          component: resolve => require(['../components/page/user/org.vue'], resolve),
        }
      ]
    },
    {
      path: '/login',
      component: resolve => require(['../components/page/login'], resolve)
    }
  ]
})

//  判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => {
  console.log(to.fullPath)
  next();
  /*if ('/login' === to.fullPath) {
    next();
  } else {
    console.log('router:', to.fullPath)
    console.log(store.getters.isLogin)
    if (store.getters.isLogin) {
      next()
    } else {
      next('/login')
    }
  }*/
})
export default router
